package com.lzh.edu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzh.commonutils.CommonResult;
import com.lzh.edu.entity.Course;
import com.lzh.edu.entity.Teacher;
import com.lzh.edu.service.CourseService;
import com.lzh.edu.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/edu/front")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "前台系统获取讲师与课程")
    @GetMapping("/getData")
    public CommonResult index() {
        //查询前8条热门课程
//        QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<>();
//        courseQueryWrapper.orderByDesc("id");
//        courseQueryWrapper.last("limit 8");
//        List<Course> courseList = courseService.list(courseQueryWrapper);
        List<Course> courseList = courseService.getcourseByLimit();
        //查询前4条讲师
//        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
//        teacherQueryWrapper.orderByDesc("id");
//        teacherQueryWrapper.last("limit 4");
//        List<Teacher> teacherList = teacherService.list(teacherQueryWrapper);
        List<Teacher> teacherList = teacherService.getTeacherLimit();
        return CommonResult.ok().data("courses",courseList).data("teachers",teacherList);
    }
}
